import { 
  queryUserGrade, 
  addUserGrade,
  removeUserGrade,
  updateUserGrade,
  levelTypeList,
  levelTypeValue,
  queryTreeOrgList,
  queryOrgList, 
  addUserRole,
  queryListForLevelScore,
} from '@/services/bnsConfig/userGrade';

export default {
  namespace: 'userGrade',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryUserGrade, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addUserGrade, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeUserGrade, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateUserGrade, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },


   * levelTypeList({payload, callback}, {call, put}) {
      const response = yield call(levelTypeList, payload);
      yield put({
        type: 'savelevelTypeList',
        payload: response,
      });
      if (callback) callback(response);
    },

    * levelTypeValue({payload, callback}, {call, put}) {
      const response = yield call(levelTypeValue, payload);
      yield put({
        type: 'savelevelTypeValue',
        payload: response,
      });
      if (callback) callback(response);
    },
    * getTree({payload,callback}, {call, put}) {
      const response = yield call(queryTreeOrgList, payload);
      yield put({
        type: 'saveTree',
        payload: response,
      });
      if (callback) callback(response);
    },
    * getList({payload, callback}, {call, put}) {
      const response = yield call(queryOrgList, payload);
      yield put({
        type: 'saveList',
        payload: response,
      });
      if (callback) callback(response);
    },
    * bindUserRole({payload, callback}, {call, put}) {
      const response = yield call(addUserRole, payload);
      yield put({
        type: 'saveRole',
        payload: response,
      });
      if (callback) callback(response);
    },
    * listForLevelScore({payload, callback}, {call, put}) {
      const response = yield call(queryListForLevelScore, payload);
      yield put({
        type: 'savelistForLevelScore',
        payload: response,
      });
      if (callback) callback(response);
    },

  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },

  },
};
